package com.example.discover_model.tabs;

import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewbinding.ViewBinding;

import com.example.common.mvvm.view.BaseFragment;
import com.example.discover_model.FindAdapter;
import com.example.discover_model.FindViewModel;
import com.example.discover_model.databinding.FragmentAttentionBinding;
import com.example.discover_model.entity.DataDTO;
import com.example.discover_model.entity.DataDTOX;
import com.example.widget_sdk.FindDecoration;

import java.util.List;
import java.util.Map;

/**
 * 关注页面
 *
 */
public class AttentionFragment extends BaseFragment<FragmentAttentionBinding, FindViewModel> {
    private RecyclerView findRecycler;
    private List<DataDTO> dataList;

    @Override
    public void receiveData(Map<String, Object> data) {
        DataDTOX dataDTOX = (DataDTOX) data.get("FINDDATA");

        dataList = dataDTOX.data;
        FindAdapter adapter = (FindAdapter) findRecycler.getAdapter();
        if (adapter==null){
            adapter = new FindAdapter();
            findRecycler.setLayoutManager(new LinearLayoutManager(findRecycler.getContext(), RecyclerView.VERTICAL,false));
            findRecycler.setAdapter(adapter);
            findRecycler.addItemDecoration(new FindDecoration(getContext()));
            adapter.setNewInstance(dataList);
        }else {
            adapter.getData().clear();
            adapter.setNewInstance(dataList);
        }
    }

    @Override
    public View bindLayout() {
        return v.getRoot();
    }

    @Override
    public ViewBinding initBind() {
        return FragmentAttentionBinding.inflate(inflater);
    }

    @Override
    public void initView() {
        findRecycler = v.recommendRecycler;
    }

    @Override
    public void initData() {

    }
}
